package simtools.xml.test;

import java.net.URL;
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

/**
 * Basic JDOM Example
 * Outputs any external XML file specified on the command line
 * Please specify absolute URL
 * Example usage:
 * java jdom2 "http://p.moreover.com/cgi-local/page?c=Biotech%20news&o=xml"
 */

public class Jdom2 {

	// Download and Output XML File
	public void process(String url) {
		try {
			//  Use SAXBuilder
			SAXBuilder builder = new SAXBuilder();
			Document doc = builder.build(new URL(url));

			//  Use XMLOutputter
			XMLOutputter out = new XMLOutputter();
			out.output(doc, System.out);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		String url = "http://p.moreover.com/cgi-local/page?c=Biotech%20news&o=xml";
		System.out.println("JDOM2 Example");
		System.out.println("Downloading file:  " + url);
		Jdom2 app = new Jdom2();
		app.process(url);
	}

}